window=global;
base64Encode = function(n) {
        if (window.btoa)
            return window.btoa(n);
        var e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
        return function(n) {
            var t, r, i, o, a, s, c;
            for (r = i = 0,
            o = n.length,
            s = (o -= a = o % 3) / 3 << 2,
            a > 0 && (s += 4),
            t = new Array(s); r < o; )
                c = n.charCodeAt(r++) << 16 | n.charCodeAt(r++) << 8 | n.charCodeAt(r++),
                t[i++] = e[c >> 18] + e[c >> 12 & 63] + e[c >> 6 & 63] + e[63 & c];
            return 1 == a ? (c = n.charCodeAt(r++),
            t[i++] = e[c >> 2] + e[(3 & c) << 4] + "==") : 2 == a && (c = n.charCodeAt(r++) << 8 | n.charCodeAt(r++),
            t[i++] = e[c >> 10] + e[c >> 4 & 63] + e[(15 & c) << 2] + "="),
            t.join("")
        }(n)
    }
encrypt = function(n) {
        var e, t = "e98ae8878c264a7e";
        function r(n) {
            if (/^[\x00-\x7f]*$/.test(n))
                return n;
            for (var e = [], t = n.length, r = 0, i = 0; r < t; ++r,
            ++i) {
                var o = n.charCodeAt(r);
                if (o < 128)
                    e[i] = n.charAt(r);
                else if (o < 2048)
                    e[i] = String.fromCharCode(192 | o >> 6, 128 | 63 & o);
                else {
                    if (!(o < 55296 || o > 57343)) {
                        if (r + 1 < t) {
                            var a = n.charCodeAt(r + 1);
                            if (o < 56320 && 56320 <= a && a <= 57343) {
                                var s = 65536 + ((1023 & o) << 10 | 1023 & a);
                                e[i] = String.fromCharCode(240 | s >> 18 & 63, 128 | s >> 12 & 63, 128 | s >> 6 & 63, 128 | 63 & s),
                                ++r;
                                continue
                            }
                        }
                        throw new Error("Malformed string")
                    }
                    e[i] = String.fromCharCode(224 | o >> 12, 128 | o >> 6 & 63, 128 | 63 & o)
                }
            }
            return e.join("")
        }
        function i(n) {
            return 4294967295 & n
        }
        function o(n, e, t, r, i, o) {
            return (t >>> 5 ^ e << 2) + (e >>> 3 ^ t << 4) ^ (n ^ e) + (o[3 & r ^ i] ^ t)
        }
        function a(n, e) {
            var t, r = n.length, i = r >> 2;
            0 != (3 & r) && ++i,
            e ? (t = new Array(i + 1))[i] = r : t = new Array(i);
            for (var o = 0; o < r; ++o)
                t[o >> 2] |= n.charCodeAt(o) << ((3 & o) << 3);
            return t
        }
        return null == n || 0 === n.length ? n : (n = r(n),
        t = r(t),
        function(n, e) {
            var t = n.length
              , r = t << 2;
            if (e) {
                var i = n[t - 1];
                if (i < (r -= 4) - 3 || i > r)
                    return null;
                r = i
            }
            for (var o = 0; o < t; o++)
                n[o] = String.fromCharCode(255 & n[o], n[o] >>> 8 & 255, n[o] >>> 16 & 255, n[o] >>> 24 & 255);
            var a = n.join("");
            return e ? a.substring(0, r) : a
        }(function(n, e) {
            var t, r, a, s, c, l, d = n.length, u = d - 1;
            for (r = n[u],
            a = 0,
            l = 0 | Math.floor(6 + 52 / d); l > 0; --l) {
                for (s = (a = i(a + 2654435769)) >>> 2 & 3,
                c = 0; c < u; ++c)
                    t = n[c + 1],
                    r = n[c] = i(n[c] + o(a, t, r, c, s, e));
                t = n[0],
                r = n[u] = i(n[u] + o(a, t, r, u, s, e))
            }
            return n
        }(a(n, !0), ((e = a(t, !1)).length < 4 && (e.length = 4),
        e)), !1))
    }
wugan_par = 'appid=201802274651|ctxid=c4e58492218ecf68874b0492bfddae68|type=init|u=|d=67,31,0:71,29,16:77,25,32:79,24,48|a=18320975328|p=Aafbike2985|t=361|r=0.18793475127986436';
wugan_get='appid=201802274651|ctxid=c4e58492218ecf68874b0492bfddae68|a=18320975328|p=Aafbike2985|r=0.2812938718141643';
yougan_par='appid=201802274651|ctxid=c4e58492218ecf68874b0492bfddae68|type=slide|u=137|d=0,0,0:3,0,278:7,0,294:10,0,310:12,0,334:15,0,366:16,0,430:17,0,511:18,0,534:22,0,550:27,0,566:34,0,582:40,0,598:49,0,614:58,0,630:64,0,646:71,0,662:76,0,678:85,0,695:95,0,710:104,0,726:109,0,742:114,0,758:116,0,774:120,0,790:125,0,806:130,2,822:132,3,838:135,3,862:136,3,911:137,4,926:138,4,958:139,4,982:141,4,1030:140,4,1190:139,4,1206:137,5,1230:136,6,1262:137,6,1711:137,6,2030|a=18320975328|p=Aafbike2985|t=2030|r=0.22240925615767448'
yougan_get='appid=201802274651|ctxid=8032861114c4874b661bc049df30a363|a=18320975328|p=Aafbike2985|r=0.3561128682548459'

// "7e821179cb724adc4fd80b095d861315"
// init
// slide

// 'appid=201802274651|ctxid=d60a9778ecf8bf8571e9248257ddba0b|type=word|u=PH9TX|d=0,0,0:68,70,1765:28,70,1781:6,70,1797:3,70,1813:2,68,1829:1,66,1845:0,62,1861:0,58,1877:0,56,1893:0,54,1917:0,53,1933:0,52,1965:0,51,1981:3,49,1997:5,47,2013:9,46,2029:14,45,2045:22,43,2061:31,40,2077:37,37,2093:40,36,2109:41,36,2126:41,35,2150|a=18320975328|p=Aafbike2985|t=2869|r=0.45659002308573726'
// 'appid=201802274651|ctxid=ca653f16793170d94885980105406775|type=click|u=38,106,0:229,74,1479:213,32,2167|d=48,102,0:52,106,80:75,113,95:105,117,111:137,121,127:165,125,144:179,127,159:185,128,175:187,130,191:188,130,207:189,131,231:191,131,247:192,132,271:193,133,287:195,133,320:195,134,336:196,134,368:199,134,383:201,134,407:204,134,423:207,134,439:210,134,455:217,134,471:221,134,487:223,134,503:225,134,519:227,134,535:230,134,560:231,134,575:232,134,599:233,134,631:234,134,647:235,134,663:236,134,679:238,134,703:239,134,768:239,135,1536:236,142,1551:234,147,1567:232,154,1583:231,157,1599:229,161,1616:229,165,1631:228,166,1647:228,167,1672:228,168,1695:227,169,1760:227,170,1783:226,171,1807:225,173,1823:224,173,1848:223,174,1879:223,175,1944:223,176,2015:220,169,2263:215,155,2279:208,142,2295:197,126,2311:175,108,2327:149,96,2344:126,84,2359:110,77,2375:94,70,2391:87,66,2407:83,63,2423:81,62,2439:80,62,2455:80,60,2488:79,60,2511:79,59,2536:78,58,2552:74,54,2567:67,46,2583:59,39,2599:55,36,2615|a=18320975328|p=Aafbike2985|t=2935|r=0.6774870249151681'
function get_cap(account,pwd,appid,cid) {
    wugan_get=`appid=${appid}|ctxid=${cid}|a=${account}|p=${pwd}|r=`+Math.random();
    // yougan_get=`appid=${appid}|ctxid=${cid}|a=18320975328|p=Aafbike2985|r=0.3561128682548459`
    res=base64Encode(encrypt(wugan_get))
    return res
}
function validate(account, pwd, type, appid, cid, dist, track_str, t) {
    let par;
    if (type == "init") {
        par = `appid=${appid}|ctxid=${cid}|type=${type}|u=|d=73,20,0:73,4,16:73,1,297:72,5,312:72,7,337:70,7,384:70,8,432|a=${account}|p=${pwd}|t=648|r=` + Math.random();
    } else if (type == "slide") {
        par = `appid=${appid}|ctxid=${cid}|type=${type}|u=${dist}|d=${track_str}|a=${account}|p=${pwd}|t=${t}|r=` + Math.random();
    } else if (type == "word") {
        par = `appid=${appid}|ctxid=${cid}|type=${type}|u=${dist}|d=0,0,0:68,70,1765:28,70,1781:6,70,1797:3,70,1813:2,68,1829:1,66,1845:0,62,1861:0,58,1877:0,56,1893:0,54,1917:0,53,1933:0,52,1965:0,51,1981:3,49,1997:5,47,2013:9,46,2029:14,45,2045:22,43,2061:31,40,2077:37,37,2093:40,36,2109:41,36,2126:41,35,2150|a=${account}|p=${pwd}|t=2869|r=` + Math.random();
    } else if (type == "click") {
        // 轨迹写死
        const fixedTrack = "48,102,0:52,106,80:75,113,95:105,117,111:137,121,127:165,125,144:179,127,159:185,128,175:187,130,191:188,130,207:189,131,231:191,131,247:192,132,271:193,133,287:195,133,320:195,134,336:196,134,368:199,134,383:201,134,407:204,134,423:207,134,439:210,134,455:217,134,471:221,134,487:223,134,503:225,134,519:227,134,535:230,134,560:231,134,575:232,134,599:233,134,631:234,134,647:235,134,663:236,134,679:238,134,703:239,134,768:239,135,1536:236,142,1551:234,147,1567:232,154,1583:231,157,1599:229,161,1616:229,165,1631:228,166,1647:228,167,1672:228,168,1695:227,169,1760:227,170,1783:226,171,1807:225,173,1823:224,173,1848:223,174,1879:223,175,1944:223,176,2015:220,169,2263:215,155,2279:208,142,2295:197,126,2311:175,108,2327:149,96,2344:126,84,2359:110,77,2375:94,70,2391:87,66,2407:83,63,2423:81,62,2439:80,62,2455:80,60,2488:79,60,2511:79,59,2536:78,58,2552:74,54,2567:67,46,2583:59,39,2599:55,36,2615";
        par = `appid=${appid}|ctxid=${cid}|type=click|u=${dist}|d=${fixedTrack}|a=${account}|p=${pwd}|t=${t}|r=` + Math.random();
    }
    let res = base64Encode(encrypt(par));
    return res;
}
// console.log(init(wugan_par)+"\n")
// console.log(init(wugan_get)+"\n")
// console.log(init(yougan_par)+"\n")
// console.log(init(yougan_get))